package com.stackexchange.webapis
{
	import com.stackexchange.webapis.client.StackExchangeService;
	import com.stackexchange.webapis.events.StackExchangeResultEvent;
	
	import org.flexunit.Assert;
	import org.flexunit.asserts.assertEquals;
	import org.flexunit.asserts.assertNotNull;
	import org.flexunit.asserts.assertNull;
	import org.flexunit.asserts.assertTrue;
	import org.flexunit.async.Async;

	public class AnswersTest extends BaseTest
	{		

		[Test(async)]
		public function answersGetOneAnswer():void
		{
			function handleResult(event:StackExchangeResultEvent, passThroughData:Object):void
			{
				assertTrue(event.success);
				assertNotNull(event.data.answers);
			}
			
			var passThroughData:Object = new Object();
		    
			service.answers.addEventListener(StackExchangeResultEvent.ANSWERS_GET, 
		               Async.asyncHandler(this, handleResult, TestConstants.timeout, passThroughData, handleTimeout), 
		               false, 0, true );
			service.answers.get([TestConstants.answerId]);
		}
		
		[Test(async)]
		public function answersGetComments():void
		{
			function handleResult(event:StackExchangeResultEvent, passThroughData:Object):void
			{
				assertTrue(event.success);
				assertNotNull(event.data.answers);
				assertEquals(event.data.answers.comments.length, 1);
			}
			
			var passThroughData:Object = new Object();
		    service.answers.addEventListener(StackExchangeResultEvent.ANSWERS_GET_COMMENTS, 
		               Async.asyncHandler(this, handleResult, TestConstants.timeout, passThroughData, handleTimeout), 
		               false, 0, true );
		    service.answers.getComments([TestConstants.answerWithComment]);
		}
		
		[Test(async)]
		public function answersGetNoAnswers():void
		{
			function handleResult(event:StackExchangeResultEvent, passThroughData:Object):void
			{
				assertTrue(event.success);
				assertEquals(event.data.answers.answers, 0);
			}
			
			var passThroughData:Object = new Object();
			
			service.answers.addEventListener(StackExchangeResultEvent.ANSWERS_GET, 
				Async.asyncHandler(this, handleResult, TestConstants.timeout, passThroughData, handleTimeout), 
				false, 0, true );
			service.answers.get([TestConstants.noAnswerId]);
		}
		
	}
}